<?php

function insertIngredient($recipeId,$name){
	transactionOpen();
	$dbLink = $GLOBALS["dbLink"];
	if ($dbLink) {
		$name = mysql_real_escape_string($name);
		$result = mysql_query("insert into ingredient (recipeId,name)
			values ('$recipeId','$name')",$dbLink);
		transactionClose();
		if (!$result) {
			redirectError("ingredient not inserted");
		}
	}
	else {
		transactionClose();
		redirectError("ingredient not inserted");
	}
} //end insertIngredient


function findByRecipe($recipeId){
	transactionOpen();
	$dbLink = $GLOBALS["dbLink"];
	if (($recipeId > 0) && ($dbLink)) {
		$result = mysql_query("select * from ingredient where
										recipeId = $recipeId");
		transactionClose();
		if (mysql_num_rows($result) > 0) {
			$count = mysql_num_rows($result);
			for ($i=0;$i<$count;$i++)
			$result2[$i]= mysql_fetch_assoc($result);
			return $result2;
		}
	}
	else {
		transactionClose();
		redirectError("problems with data base connection");
	}
} //end findRecipe


?>